<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .son {
      width: 200px;
      height: 100px;
      background-color: #000000;
      position: absolute;
    }
  </style>
</head>

<body>
  <div class="son"></div>
</body>
<script>
  var son = document.querySelector('div')
  function move(e) {
    var x = e.pageX
    var y = e.pageY
    son.style.top = y + 'px'
    son.style.left = x + 'px'
  }
  // onmousedown：按下鼠标键时触发
  son.onmousedown = function () {
    // addEventListener：在文档中添加事件
    document.addEventListener('mousemove', move)
  }
  // onmouseup：释放按下的鼠标键时触发
  son.onmouseup = function () {
    // removeEventListener：移除文档中的事件
    document.removeEventListener('mousemove', move)
  }
  // mousemove：鼠标移动事件
</script>

</html>